#!/bin/bash

#################################################
# 生成一个新的LogicServer
# 如sh newlogic.sh Login
#################################################

server_name=$*;
server_file=`echo $server_name|tr '[A-Z]' '[a-z]'`
server_def=`echo $server_name|tr '[a-z]' '[A-Z]'`

if [ ! -d $server_file"server" ] ; then
    cp -r logic $server_file"server";
    chmod 444 $server_file"server";
    cd $server_file"server";

    sed -i 's/class\ Server/class\ '$server_name'Server/' server.h
    sed -i 's/Server(/'$server_name'Server(/' server.h
    sed -i 's/SERVER/'$server_def'_SERVER/' server.h

    sed -i 's/Server/'$server_name'Server/' server.cpp
    sed -i 's/server.h/'$server_file'server.h/' server.cpp

    sed -i 's/Server/'$server_name'Server/' main.cpp
    sed -i 's/server.h/'$server_file'server.h/' main.cpp

    sed -i 's/server/'$server_file'server/' Makefile

    mv server.h $server_file"server.h"
    mv server.cpp $server_file"server.cpp"
else
    echo "Folder "$server_file"server Error";
fi
